package me.pplay.playtalk.activity.setting;

import java.util.ArrayList;

import me.pplay.playtalk.ApplicationTrans;
import me.pplay.playtalk.R;
import me.pplay.playtalk.activity.BaseActivity;
import me.pplay.playtalk.data.Globals;
import me.pplay.playtalk.protocol.TpChat;
import me.pplay.playtalk.protocol.bean.TPBuddyinfo;
import me.pplay.playtalk.protocol.bean.TpLanguage;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class SettingNicknameActivity extends BaseActivity {
	private TpChat tpChat;
	private ImageButton btn_back;
	private EditText editText;
	private Button btn_save;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_setting_nickname);
		super.SetOnBackClickListener((ImageButton)findViewById(R.id.viewmember_btnback));
		ApplicationTrans appState = (ApplicationTrans) getApplicationContext();
		tpChat = appState.getTpChat();

		btn_back = (ImageButton)findViewById(R.id.nickname_btnback);
		editText = (EditText)findViewById(R.id.nickname_edit);
		if(null != Globals.myInfo)
			editText.setText(Globals.myInfo.getAlias());
		btn_save = (Button)findViewById(R.id.nickname_btnsave);
		clickEvents();
	}	
	
	private void clickEvents() {
		btn_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				SettingNicknameActivity.this.finish();
			}
		});
		
		btn_save.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				TPBuddyinfo buddyinfo = new TPBuddyinfo();
				buddyinfo.setAlias(editText.getText().toString());
				tpChat.tp_chat_set_info(buddyinfo);
					if(null != Globals.myInfo){
						Globals.myInfo.setAlias(editText.getText().toString());
					}
					SettingNicknameActivity.this.finish();
			}
		});
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}
}
